package jt.classic.app.info.machining;

import org.limp.basework.MachiningException;
import org.limp.basework.SimpleBean;
import org.limp.basework.SimpleBeanMachining;
import org.limp.basework.Table;

import org.limp.mine.DataTrimmer;
import org.limp.mine.StringTool;

import java.sql.Connection;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;


/**
 * 专题/栏目信息加工类
 * @author mido
 *
 */
public class InfoMachining implements SimpleBeanMachining {
    public SimpleBean machining(SimpleBean arg0, Table arg1,
        HttpServletRequest arg2, Connection conn, int arg4)
        throws MachiningException {
        if (arg4 == 0) {
            String pid = (String) arg0.getResource().get("idparent");

            String sql = "SELECT MAX(ID_ORDER) AS ID_ORDER FROM APP_INFO_DIRECTORY WHERE ID_ID = " +
                pid;

            DataTrimmer trimmer = new DataTrimmer(conn);

            Map info = trimmer.searchSingleData(sql);

            try {
                String order = info.get("ID_ORDER").equals("") ? "0"
                                                               : (String) info.get(
                        "ID_ORDER");

                arg0.getResource()
                    .put("idorder", String.valueOf(Integer.parseInt(order) + 1));
            } catch (Exception ex) {
                throw new MachiningException("Info-Machining machine simple-bean error.",
                    ex);
            }
        }

        return arg0;
    }
}
